import Cookies from 'js-cookie'
import SHA512 from 'crypto-js/sha512'

const fields = ['sessionid', 'accountUuid', 'accountType', 'accountName', 'isAccount', 'proxyName']
export function setCookie(key: string, val: string) {
  Cookies.set(key, val)
}
export function setCookies(info = {}) {
  Object.entries(info).forEach(([key, val]) => Cookies.set(key, val))
}

export function clearCookies() {
  fields.forEach(field => Cookies.remove(field))
}

// 密码统一加密
export function encrypt(password: string) {
  return SHA512(password).toString()
}

export function isProxyFn() {
  return Cookies.get('accountType') === 'Proxy'
}
export function isLoginFn(): boolean {
  return !!Cookies.get('sessionid')
}
export function isAccountFn(): boolean {
  return Cookies.get('isAccount') === 'true'
}
